#include "zone.h"

zone::zone()
{
}

zone::zone(const zone& zone_)
{
	std::vector<irr::core::vector3df>::const_iterator it = zone_.points__.begin();
	while (it != zone_.points__.end())
	{
		points__.push_back(*it);
		it++;
	}

	name__ = zone_.name__;

	plane__ = zone_.plane__;

	std::vector<int>::const_iterator it2 = zone_.seg_indexes__.begin();
	while (it2 != zone_.seg_indexes__.end())
	{
		seg_indexes__.push_back(*it2);
		it2++;
	}
}

zone::~zone()
{
}

zone& zone::operator=(const zone& zone_)
{
	std::vector<irr::core::vector3df>::const_iterator it = zone_.points__.begin();
	while (it != zone_.points__.end())
	{
		points__.push_back(*it);
		it++;
	}

	name__ = zone_.name__;

	plane__ = zone_.plane__;

	std::vector<int>::const_iterator it2 = zone_.seg_indexes__.begin();
	while (it2 != zone_.seg_indexes__.end())
	{
		seg_indexes__.push_back(*it2);
		it2++;
	}

	return *this;
}

std::string& zone::getName()
{
	return name__;
}

std::vector<irr::core::vector3df>& zone::getPoints()
{
	return points__;
}

std::vector<int>& zone::getSegments()
{
	return seg_indexes__;
}

irr::core::plane3df& zone::getPlane()
{
	return plane__;
}

void zone::calculatePlane()
{
	plane__.setPlane(points__[0], points__[1], points__[2]);
}

// TODO: test this
bool operator==(const zone& z1, const zone& z2)
{
	if (z1.name__ != z1.name__)
		return false;
	
	bool ret = true;
	for (int i=0; i<4; i++)
		ret &= z1.points__[i] == z2.points__[i];
	
	return ret;
}

